package com.keke.myblogv1.updatelog.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.keke.myblogv1.article.dto.QueryArticleByPageDTO;
import com.keke.myblogv1.common.result.ResponseResult;
import com.keke.myblogv1.updatelog.dto.QueryUpdateLogByPageDTO;
import com.keke.myblogv1.updatelog.entity.MyBlogUpdateLog;
import com.keke.myblogv1.updatelog.mapper.MyBlogUpdateLogMapper;
import com.keke.myblogv1.updatelog.service.MyBlogUpdateLogService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Derrick
 * @since 2022-07-31
 */
@RestController
@RequestMapping("/updatelog")
public class MyBlogUpdateLogController {

    @Resource
    private MyBlogUpdateLogService myBlogUpdateLogService;

    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public ResponseResult<List<MyBlogUpdateLog>> getMyBlogUpdateLogList(){
        List<MyBlogUpdateLog> myBlogUpdateLogList = null;
        try{
            myBlogUpdateLogList = myBlogUpdateLogService.getMyBlogUpdateLogList();
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error();
        }
        return ResponseResult.success(myBlogUpdateLogList);
    }

    @RequestMapping(value = "/listByPage",method = RequestMethod.GET)
    public ResponseResult<Page<MyBlogUpdateLog>> getMyBlogUpdateLogListByPage(QueryUpdateLogByPageDTO queryUpdateLogByPageDTO){
        Page<MyBlogUpdateLog> myBlogUpdateLogList = null;
        try{
            myBlogUpdateLogList = myBlogUpdateLogService.getMyBlogUpdateLogListByPage(queryUpdateLogByPageDTO);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error();
        }
        return ResponseResult.success(myBlogUpdateLogList);
    }

    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public ResponseResult updateUpdateLog(@RequestBody MyBlogUpdateLog myBlogUpdateLog){
        boolean result = false;
        try{
            result = myBlogUpdateLogService.updateUpdateLog(myBlogUpdateLog);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error();
        }
        if(result){
            return ResponseResult.success();
        }else{
            return ResponseResult.error();
        }
    }
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    public ResponseResult deleteUpdateLog(@RequestBody MyBlogUpdateLog myBlogUpdateLog){
        boolean result = false;
        try{
            result = myBlogUpdateLogService.deleteUpdateLog(myBlogUpdateLog);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error();
        }
        if(result){
            return ResponseResult.success();
        }else{
            return ResponseResult.error();
        }
    }


}
